<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use app\index\model\UsersModel;
/**
 * 后台首页控制器
 */
class User extends BaseController{

	/**
	 * 用户列表
	 */
    public function login(){
        $userName = input('post.username');
        $password = input('post.password');
        if (!$userName || !$password) {
            return $this->ajaxReturn(400, null, '用户名密码不能为空');
        }

        $model = new UsersModel();
        $map['username'] = $userName;
        $map['password'] = $password;
        $user = $model->where($map)->find();
        if ($user) {
            session("username",$userName);
            session("uid",$user['id']);
            return $this->ajaxReturn(200, $user, '用户名密码不能为空');
        }else{
            return $this->ajaxReturn(401, $user, '用户名密码不匹配');
        }
    }

    public function logout(){
        session('username',null);
        return $this->ajaxReturn(200, null, '用户名密码不能为空');
    }

}
